﻿$(function(){
	function shareaside(o){
		//参数说明：self.tit说明文字，self.pic小图片，self.url分享要链接到的地址
		var self = this;
		self.tit = o.tit;
		self.pic = o.pic;
    self.titsummary = o.intro;
		self.url = o.url;
	}
	shareaside.prototype={
		postToWb:function(){
			var _t = encodeURI(this.tit);//当前页面title，使用document.title
			var _url = encodeURIComponent(this.url);//当前页的链接地址使用document.location
			var _appkey = encodeURI("appkey");//你从腾讯获得的appkey，如果有appkey,直接写入key值，例如：_appkey=123456
			var _pic = encodeURI(this.pic);//（例如：var _pic='图片url1|图片url2|图片url3....）
			var _site = '';//你的网站地址
			var _u = 'http://v.t.qq.com/share/share.php?title='+_t+'&url='+_url+'&appkey='+_appkey+'&site='+_site+'&pic='+_pic;
			window.open( _u,'分享到腾讯微博');
		},
		//参数说明：title标题，summary摘要，pic小图片，url分享要链接到的地址
		postToQzone:function (){
			var _url = encodeURIComponent(this.url);//当前页的链接地址使用document.location
			var _t = encodeURI(this.tit);//当前页面title，使用document.title
			//var _pic = encodeURI(this.pic);//（例如：var _pic='图片url1|图片url2|图片url3....）
			var _summary=encodeURIComponent('');
			var _u = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+_url+'&title='+_t+'&pics=&summary='+_summary;
			window.open( _u,'分享到QQ空间和朋友网');
		},
		shareToSina:function(){
			var url = "http://v.t.sina.com.cn/share/share.php",
			_url = this.url,
			_title = this.tit,
			_appkey = '',
			_ralateUid = '',
			c = '', pic = this.pic;
			c = url + "?url=" + encodeURIComponent(_url) + "&appkey=" + _appkey + "&title=" + _title + "&pic=" + pic + "&ralateUid=" + _ralateUid + "&language=";
			window.open(c, "shareQQ", "height=480,width=608,top=100,left=200,toolbar=no,menubar=no,resizable=yes,location=yes,status=no");
		},
		share2qq:function (){
			//var l = document.getElementById('imgBox').getElementsByTagName('img')[0];
			var a = "http://connect.qq.com/widget/shareqq/index.html",
			d = this.url,
			m = this.tit,
			pic=this.pic,
			pl = '\u52a0\u70b9\u8bc4\u8bba\u5427...',
			b = "",
			x = window.screen.width,
			y = window.screen.height;
			h = "", k = ""; //g = l.join("||")||"";
			k = a + "?url=" + encodeURIComponent(d) + "&showcount=0&desc=" + encodeURIComponent(pl) + "&summary=" +  encodeURIComponent(this.titsummary) + "&title="+ encodeURIComponent(m) + "&pics="+ pic +"&style=203&width=19&height=22";
			window.open(k, "", "height = 680, width = 960, top = "+(y-680)/2 + ", left = " + (x-960)/2 + ", toolbar = no, menubar = no, resizable = yes, location = yes,status = no" );
		},

		init:function(){
			var _this=this;
			$('.tcwb').bind('click',function(){
				_this.postToWb();
			});
			$('.qzone').bind('click',function(){
				_this.postToQzone();
			});
			$('.sina').bind('click',function(){
				_this.shareToSina();
			});
			$('.pengyou').bind('click',function(){
				_this.share2qq();
			});
		}
	}

	var DataIMG = '';
 	//分享
	$("#articleContent img").each(function(){
		DataIMG += $(this).attr('src') + '|'; 	
	});
	var share1= new shareaside({
		"tit": $("#share_title").html(),
		"pic": DataIMG,
		"url": window.location.href,
		"intro": $("#share_intro").html()
	});
	share1.init();
	 //反回到时顶部
	$('body,html').animate({scrollTop:0},1000);
	// $('body').animate({scrollTop:0}, 'fast'); 
	/*setTimeout(function(){
	 window.scrollTo(0,1);
	},10)*/
	//隐藏当前期数
	var _qtimes = $("input[name='qstime']").val();
	$('.wqhgMod .bd ul li').each(function(){
		var _id = $(this).find('a').attr('data-id');
		if(_id == _qtimes){$(this).hide();}
	})
	//编辑时可分开
	var picHeight = [];
	var dowHeight = [];
	var mn_timer = null;
	var _wubgpro = $('#thwubg').css('display');
	// $('.daoyu_content b').css({'opacity':'0'});
	if(_wubgpro == 'block'){
		$('.pagemain_content').css({'margin-top' : '0'});
		//无背景情况
		var _thisdiv = $('.pagemain_content');
		_thisdiv.css({'opacity':'1'});
		$('#thwubg').css({'position':'absolute'});
		$('.pagemain_inner').css({'padding-top':'125px'});
		// $('.shareBox').css({'top':'329px'});
		$(".xiantiao").css({
			"position": "fixed",
			"top": 39
		});
		setTimeout(function(){
			$('.nofloat_img').each(function(){
			 	picHeight.push($(this).find('img').offset().top);
			 	dowHeight.push($(this).find('img').offset().top-180);
			});
			setObj();
		},500)
		//滚动定位
		$(window).scroll(function () {
			/*分享定位*/
			var _scrollmtop = Math.ceil(_h/2.5)-40;
			if ($(window).scrollTop() < _scrollmtop) {
				$(".xiantiao").css({
					"position": "relative",
					"top": 0
				});
			}		
			if ($(window).scrollTop() >= _scrollmtop) {
				$(".xiantiao").css({
					"position": "fixed",
					"top": 39
				});
			}
			/*分享定位*/
	    if ($(window).scrollTop() < 330) {
	    	$(".pagemain_content .shareBox").removeClass('shareTop')
	    } 
	    if ($(window).scrollTop() >= 330) {
	    	$(".pagemain_content .shareBox").addClass('shareTop')
	    }
		})
	}else{
		//有背景情况
		var _h = $(window).height();
		var _top = parseInt($('.shareBox').css('top'));
		$('.pagemain_content').css({'margin-top' : _h+'px'});
		$('#share_title').css({'margin-top' : '250px'});
		setTimeout(function(){
			//内容区
			$('.pagemain_content').animate({
				'margin-top' : _h/2.5,
				   'opacity' :     '1'
			}, 900,function(){})
			//标题区
			$('#share_title').animate({
				'margin-top' : 0
			},2500,'linear',function(){
				$('.nofloat_img').each(function(){
				 	picHeight.push($(this).find('img').offset().top);
				 	dowHeight.push($(this).find('img').offset().top-180);
				});
				setObj();
			})
		},2000)
		//滚动定位
		$(window).scroll(function () {
			/*分享定位*/
			var _scrollmtop = Math.ceil(_h/2.5)-40;
			if ($(window).scrollTop() < _scrollmtop) {
				$(".xiantiao").css({
					"position": "relative",
					"top": 0
				});
			}		
			if ($(window).scrollTop() >= _scrollmtop) {
				$(".xiantiao").css({
					"position": "fixed",
					"top": 39
				});
			}
			/*分享定位*/
	    if ($(window).scrollTop() < 630) {
	    	$(".pagemain_content .shareBox").removeClass('shareTop')
	    } 
	    if ($(window).scrollTop() >= 630) {
	    	$(".pagemain_content .shareBox").addClass('shareTop')
	    }
		})
	}
	/*
	var _a1 = $('.autor_content .acone b').text();
	var _t1 = $('.autor_content .acone span').text();
	var _a2 = $('.autor_content .actwo b').text();
	var _t2 = $('.autor_content .actwo span').text();
	$('.bottomautor .tleft b').html(_a1);
	$('.bottomautor .tleft span').html(_t1);
	$('.bottomautor .tright b').html(_a2);
	$('.bottomautor .tright span').html(_t2);
	*/
  var _totalnum = $('#articleContent .nofloat_img img').length;
  $("#articleContent .nofloat_img .totalNum").html(_totalnum);
/*滚动*/
var ns = 0;
var _firstclick = true;
var _countheight = 0;
function keyDown(e)                                      
{
  key = (ietype)? e.which : event.keyCode
  if (key == 100 || key == 40) moveObj(1,4);
  if (key == 117 || key == 38) moveObj(1,5);
}
function setObj()
{
  ietype = (document.layers) ? 1 : 0;                                   
  document.onkeydown = keyDown;                                                
  if (ietype) document.captureEvents(Event.keydown | Event.keyup);
}
$('.autor_content a').each(function(){
  var _a = $(this).find('b').html()
  if(_a == ''){$(this).hide();}
})
var _contentl = $('.mainContent .tleft b').html();
if(_contentl == ''){$('.mainContent .tleft').html("");$('.mainContent .tright').css({'margin-left':'-7px'});}
var _contentr = $('.mainContent .tright b').html();
if(_contentr == ''){$('.mainContent .tright').html("");$('.mainContent .tleft').css({'margin-right':'-7px'});}
function moveObj(t,u)                                   
	//移动图片的方法
	{
		var _len = $('#articleContent .nofloat_img').length;
	  if(u==4 && (ns<(_len-1))){
	  	if(_firstclick && ns == 0){
	  		$(document).scrollTop(dowHeight[0]);
	  		_firstclick = false;
	  	}else{
	  		ns++;
	  		$(document).scrollTop(dowHeight[ns]);
	  	}	
	  }
		//上
		if(u==5 && (ns>=0)){
			if(ns == 0){
				$(document).scrollTop(0);
				_firstclick = true;
			}else{
				ns--;
				$(document).scrollTop(picHeight[ns]);
			}
		}
	}

})
/*  |xGv00|a3ae21f419b8797a6ae7dd35c9674edf */